﻿using System.Windows;
using System.Windows.Controls;
using System.Windows.Media;
using TeBigScreenWpf.Common;

namespace TeBigScreenWpf.Views
{
    internal class TeTitleGroup : ContentControl
    {
        private readonly double CenterLineWidth = 1280;
        private readonly double CenterLineThickness = 2;

        private readonly double OffsetX = 12;
        private readonly double OffsetY = 20;

        private readonly Brush CenterLineBrushBackground = Themes.TeTitleGroup.CenterLineBrushBackground;
        private readonly Brush CenterLineBrushForeground = Themes.TeTitleGroup.CenterLineBrushForeground;
        private readonly Brush LeftWingsLineBrush = Themes.TeTitleGroup.LeftWingsLineBrush;
        private readonly Brush RightWingsLineBrush = Themes.TeTitleGroup.RightWingsLineBrush;

        public TeTitleGroup()
        {
        }

        private void DrawBackground(DrawingContext dc)
        {
            var bounds = new Rect(RenderSize);

            //中间梯形线
            {
                PathGeometry geo = new PathGeometry();

                geo.AddLines(new Point[]
                {
                    //new Point(bounds.Left, bounds.Bottom - OffsetY),
                    new Point(bounds.Left + (bounds.Width - CenterLineWidth) / 2 - OffsetX, bounds.Bottom - OffsetY),
                    new Point(bounds.Left + (bounds.Width - CenterLineWidth) / 2, bounds.Bottom),
                    new Point(bounds.Right - (bounds.Width - CenterLineWidth) / 2, bounds.Bottom),
                    new Point(bounds.Right - (bounds.Width - CenterLineWidth) / 2 + OffsetX, bounds.Bottom - OffsetY),
                    //new Point(bounds.Right, bounds.Bottom - OffsetY),
                });

                dc.DrawGeometry(null, new Pen(CenterLineBrushBackground, CenterLineThickness * 2), geo);
                dc.DrawGeometry(null, new Pen(CenterLineBrushForeground, CenterLineThickness), geo);
            }

            //左边线
            {
                PathGeometry geo = new PathGeometry();

                geo.AddLines(new Point[]
                {
                    new Point(bounds.Left, bounds.Bottom - OffsetY),
                    new Point(bounds.Left + (bounds.Width - CenterLineWidth) / 2 - OffsetX, bounds.Bottom - OffsetY),
                });

                dc.DrawGeometry(null, new Pen(LeftWingsLineBrush, CenterLineThickness), geo);
            }

            //右边线
            {
                PathGeometry geo = new PathGeometry();

                geo.AddLines(new Point[]
                {
                    new Point(bounds.Right - (bounds.Width - CenterLineWidth) / 2 + OffsetX, bounds.Bottom - OffsetY),
                    new Point(bounds.Right, bounds.Bottom - OffsetY),
                });

                dc.DrawGeometry(null, new Pen(RightWingsLineBrush, CenterLineThickness), geo);
            }
        }

        protected override void OnRender(DrawingContext dc)
        {
            base.OnRender(dc);

            DrawBackground(dc);
        }
    }
}